import React from "react";
import { Navigate, useLocation } from "react-router-dom";
import RBACManager from "../../utils/rbacManager";

export const AuthGuard = ({ children }) => {
  const location = useLocation();
  const isAuthenticated = RBACManager.isAuthenticated();

  if (!isAuthenticated) {
    // 保存尝试访问的URL
    return <Navigate to="/login" state={{ from: location }} replace />;
  }

  return children;
};
